package com.joeljhou.project.core.listener;

import com.joeljhou.project.core.SerialPortManager;
import com.joeljhou.project.form.Component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CloseListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        // 处理按钮点击事件
        Component component = Component.getInstance();

        Boolean isClose = SerialPortManager.closePort();
        if (isClose) {
            JComboBox portComboBox = component.getPortComboBox();
            JTextField pullTextField = component.getPullTextField();
            portComboBox.setEnabled(true);
            pullTextField.setEnabled(true);
            component.printLog("指定串行端口 断开连接成功", Color.BLACK);
            return;
        }
        component.printLog("指定串行端口 断开连接失败");
    }
}
